﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Windows.Forms;

public partial class _Default : System.Web.UI.Page
{
    //Literal Information = new Literal();
    protected void Page_Load(object sender, EventArgs e)
    {
        ImageButton1.ImageUrl = "~/Picture.aspx";
        if (Session["CheckCode"] == null) {
        }

        //    MessageBox.Show( "对不起，验证码生成错误！");

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection();
        cn.ConnectionString = "Data Source=.;Initial Catalog=HotelManagement;Integrated Security=True";

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cn;
        cmd.CommandText = "select * from customer where teliphone =@teliphone and pasword=@pasword";
        cmd.Parameters.Add("@teliphone", System.Data.SqlDbType.NChar, 11).Value = teliphone.Text;
        cmd.Parameters.Add("@pasword", System.Data.SqlDbType.NChar, 100).Value = pasword.Text;
        cn.Open();
        SqlDataReader dr = cmd.ExecuteReader();       
        if (teliphone.Text.Length == 0)
            MessageBox.Show("请输入用户名！");
        else
        {
            if (pasword.Text.Length == 0)
                MessageBox.Show("请输入密码！");
        //    else if (txtCode.Text.ToString() != Session["CheckCode"].ToString())
        //    {
        //        Information.Text = "对不起，验证码不正确，请重新输入！";
        //    }
        //    else { }
        }

        if (dr.Read())
        {
            if (txtCode.Text.ToString() != Session["CheckCode"].ToString())
            {
                MessageBox.Show("对不起，验证码不正确，请重新输入！");
                
            }
            else
            {

                Session["teliphone"] = teliphone.Text.Trim();   //将电话号码存入session变量中
                Response.Redirect("index.aspx");
            }
            
        }
        else
        {
            Literal lit = new Literal();
            lit.Text = "<script language='javascript'>window.alert('登录失败')</script>";
            Page.Controls.Add(lit);
        }
        cn.Close();
        
    }
}